package com.kaifamiao.N0808;

import java.util.*;

/**
 * MyList 类， 数据类型
 *   容器，里面可以存放多个 元素. 变量， 数组
 *   弥补数组的缺点： 固定长度
 *   优点： 用户不用关注内部细节（不用管容器的大小）, 随机访问
 *   银行系统， accounts  --> MyList  --> List
 */
public class MyList implements List {

    // 内部容器
    private Object[] objs;

    // 元素的个数
    private int count;

    // 负载因子
    private float capacity;

    public MyList(){

        this(10);

    }

    public MyList(int size){

        if (size >= 0){
            objs = new Object[size];
        }else{
            objs = new Object[10];
        }
        capacity = 0.8F;

    }

    public MyList(Object[] objs){

        this.objs = objs;
        count = objs.length;
        capacity = 0.8F;

    }

    @Override
    public int size() {

        return count;

    }

    @Override
    public boolean isEmpty() {

        return count == 0;

    }

    @Override
    public boolean contains(Object o) {

        return count == 0;

    }

    @Override
    public Iterator iterator() {

        return null;

    }

    @Override
    public Object[] toArray() {

        return Arrays.copyOf(objs,count);

    }

    @Override
    public boolean add(Object o) {

        if (count >= objs.length * capacity) {
            // 扩容
            grow();
        }
        objs[count] = o;
        count ++;
        return true;
    }

    //扩容
    private void grow(){
        int oldSize = objs.length;
        // 1.5 倍
        int newSize = oldSize + (oldSize >> 1);
        // 将原来的元素复制到新的容器(数组)中
        objs = Arrays.copyOf(objs, newSize);
    }

    @Override
    public boolean remove(Object o) {
        return false;
    }

    @Override
    public boolean addAll(Collection c) {
        return false;
    }

    @Override
    public boolean addAll(int index, Collection c) {
        return false;
    }

    @Override
    public void clear() {

    }

    @Override
    public Object get(int index) {
        return null;
    }

    @Override
    public Object set(int index, Object element) {
        return null;
    }

    @Override
    public void add(int index, Object element) {

    }

    @Override
    public Object remove(int index) {
        return null;
    }

    @Override
    public int indexOf(Object o) {
        return 0;
    }

    @Override
    public int lastIndexOf(Object o) {
        return 0;
    }

    @Override
    public ListIterator listIterator() {
        return null;
    }

    @Override
    public ListIterator listIterator(int index) {
        return null;
    }

    @Override
    public List subList(int fromIndex, int toIndex) {
        return null;
    }

    @Override
    public boolean retainAll(Collection c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection c) {
        return false;
    }

    @Override
    public boolean containsAll(Collection c) {
        return false;
    }

    @Override
    public Object[] toArray(Object[] a) {
        return new Object[0];
    }
}